<template>
  <div class="page-container">
    <div class="link-class">
      <el-icon>
        <ChromeFilled />
      </el-icon>
      <div>
        页面 "
        <el-link :href="currentMenu?.oriURL" target="_blank" type="primary"
          >{{ currentMenu?.title }}
        </el-link>
        " 已在新窗口中打开
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { useMenuStore } from '@/stores/menu'

const menuStore = useMenuStore()

const currentMenu = computed(() => {
  return menuStore.currentMenu as LinkItem | undefined
})

defineOptions({
  //其他路由跳转到此路由
  beforeRouteEnter(to, from, next) {
    const menuStore = useMenuStore()
    const currentMenu = menuStore.getMenuById(to.meta.id as string) as LinkItem
    if (!menuStore.hasTag(currentMenu.id as string)) {
      window.open(currentMenu.oriURL)
    }
    next()
  },
  // 动态路由/多个路由复用同一个组件，之间跳转时触发
  beforeRouteUpdate(to, from, next) {
    const menuStore = useMenuStore()
    const currentMenu = menuStore.getMenuById(to.meta.id as string) as LinkItem
    if (!menuStore.hasTag(currentMenu.id as string)) {
      window.open(currentMenu.oriURL)
    }
    next()
  }
})
</script>

<style lang="scss" scoped>
.page-container {
  iframe {
    width: 100%;
    height: 100%;
    border: 0;
  }

  .link-class {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

    .el-icon {
      font-size: 100px;
      color: var(--el-color-primary);
    }
  }

  .v-enter-active,
  .v-leave-active {
    transition: opacity 0.5s ease;
  }

  .v-enter-from,
  .v-leave-to {
    opacity: 0;
  }
}
</style>
